package com.ice.work.moment.socket.call;

import com.ice.work.moment.facade.socket.request.AckRequest;
import com.ice.work.moment.facade.socket.store.GlobalStore;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.concurrent.BasicFuture;

import java.util.Objects;

/**
 * @Description task
 * @Author DELL
 * @Create 2019-06-25
 * @Since 1.0.0
 */
@Data
@NoArgsConstructor
@Slf4j
public class CheckTask implements Runnable {
    private Long key;

    @Override
    public void run() {
        try {
            AckRequest request = GlobalStore.CHECK_RESPONSE.take();
            log.info("识别结果：{}，{}",request.getId(),request.getResult());
            BasicFuture<String> response  = GlobalStore.CHECK_REQUEST.remove(request.getId());
            if (Objects.nonNull(response)) {
                response.completed(request.getResult());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
